package com.itheima.web.controller;

import com.github.pagehelper.PageInfo;
import com.itheima.domain.Orders;
import com.itheima.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/orders")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;
    //未分页
/*    @RequestMapping("/findAll.do")
    public ModelAndView findAll(@RequestParam(name = "page", required = true, defaultValue =
            "1") Integer page, @RequestParam(name = "pageSize", required = true, defaultValue = "10")
                                        Integer pageSize) throws Exception {
        List<Orders> ordersList = ordersService.findAllByPage(page, pageSize);
        ModelAndView mv = new ModelAndView();
        mv.setViewName("order-list");
        mv.addObject("ordersList", ordersList);
        return mv;
    }*/


    /*
      订单查询所有
    */
    @RequestMapping("/findAll.do")
    public ModelAndView findAll(ModelAndView mv,@RequestParam(name = "page",required = true,defaultValue = "1") int page ,@RequestParam(name = "size" ,required = true ,defaultValue = "5") int size) throws Exception {
//        ModelAndView mv=new ModelAndView();
        List<Orders> ordersList = ordersService.findAll(page,size);
        PageInfo pageInfo = new PageInfo(ordersList);
        mv.addObject("pageInfo",pageInfo);
        mv.setViewName("orders-page-list");
        return mv;
    }

/*    @RequestMapping("/findAll.do")
    public ModelAndView findAll(ModelAndView mv,@RequestParam(name = "page",required = true,defaultValue = "1") int page ,@RequestParam(name = "size" ,required = true ,defaultValue = "5") int size) throws Exception {
//        ModelAndView mv=new ModelAndView();
        List<Orders> ordersList = ordersService.findAll(page,size);
        PageInfo pageInfo = new PageInfo(ordersList);
        mv.addObject("pageInfo",pageInfo);
        mv.setViewName("orders-page-list");
        return mv;
    }*/


    /*
    订单详情
     */
    @RequestMapping("/findById.do")
    public ModelAndView findById(@RequestParam(name = "id" ,required = true) String ordersId){
        ModelAndView mv = new ModelAndView();
       Orders orders=ordersService.findById(ordersId);
       mv.addObject("orders",orders);
        mv.setViewName("orders-show");
        return mv;

    }

}
